package com.zsc.graduate.qovipan.controller;

import com.zsc.graduate.qovipan.sql.UserOpService;
import com.zsc.graduate.qovipan.util.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

/**
 * @author 枫树下奶罐
 * @version 1.0.0
 * @date 2022/4/19 18:08
 */
@RestController
@RequestMapping ("/users")
public class UserOperateController {
    private Logger log;
    @Autowired
    private UserOpService userOpService;

    @GetMapping("/getuser")
    public Long login(@RequestParam("qid") Long QID, Model model){
        log = Logger.getLogger("info.getUser");
        log.info("进入getUser进行查询");
//        log.info(String.valueOf(userOpService.findUserAll()));
        log.info("QID = " + QID);
        User user = userOpService.findByQid(QID);
        log.info("QIDs = " + user.getId());
        return user.getId();
    }

    @GetMapping("/getname")
    public Long login(@RequestParam("name") String username, Model model){
        log = Logger.getLogger("info.getUserByName");
        log.info("进入getName进行查询");
//        log.info(String.valueOf(userOpService.findUserAll()));
        log.info("username = " + username);
        User user = userOpService.findByName(username);
        log.info("QIDs = " + user.getId() + "\n" +
                "Username = " + user.getUsername());
        return user.getId();
    }
}
